package u.can.i.up.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class SystemPackages {

	private static Map<String, String> mSystemPackages = new HashMap<String, String>();

	private static void readSystemPackages() {
		if (mSystemPackages != null && !mSystemPackages.isEmpty()) {
			return;
		}
		InputStream input = Configuration.class.getClassLoader().getResourceAsStream("system.lists");
		BufferedReader br = new BufferedReader(new InputStreamReader(input));
		String line;
		try {
			while ((line = br.readLine()) != null) {
				if (!"".equals(line)) {
					line = StringUtils.splitPartStr(line, ".", 3);
					mSystemPackages.put(line, "");
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void resetSystemPackages() {
		if (mSystemPackages != null && !mSystemPackages.isEmpty()) {
			mSystemPackages.clear();
		}
	}

	public static Map<String, String> getSystemPackages() {
		readSystemPackages();
		return mSystemPackages;
	}

}
